﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32;

namespace PDF_merger
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void btnBrowse1_Click(object sender, RoutedEventArgs e)
        {
            FileNameTextBox1.Text = getFileName();
        }
        private void btnBrowse2_Click(object sender, RoutedEventArgs e)
        {
            FileNameTextBox2.Text = getFileName();
        }

        private string getFileName()
        {
            // Create OpenFileDialog
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

            // Set filter for file extension and default file extension
            dlg.DefaultExt = ".pdf";
            dlg.Filter = "Acrobat documents (.pdf)|*.pdf";

            // Display OpenFileDialog by calling ShowDialog method
            Nullable<bool> result = dlg.ShowDialog();

            // Get the selected file name and display in a TextBox
            if (result == true)
            {
                // Open document
                string filename = dlg.FileName;
                return filename;
            }
            return null;
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.FileName = "Document"; // Default file name
            dlg.DefaultExt = ".PDF"; // Default file extension
            dlg.Filter = "Acrobat documents (.pdf)|*.pdf"; // Filter files by extension

            // Show save file dialog box
            Nullable<bool> result = dlg.ShowDialog();

            // Process save file dialog box results
            if (result == true)
            {
                // Save document
                string filename = dlg.FileName;
                MergeEx me = new MergeEx();
                
                me.AddFile(FileNameTextBox1.Text);
                me.AddFile(FileNameTextBox2.Text);
                me.FirstFile = FileNameTextBox1.Text;
                me.SecondFile = FileNameTextBox2.Text;
                me.DestinationFile = filename;
                me.ExecuteTwo();
            }
        }
    }
}

